package com.fzt.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fzt.common.utils.R;
import com.fzt.system.domain.param.SysRoleParam;
import com.fzt.system.domain.vo.SysRoleVO;
import com.fzt.system.service.SysRoleService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 角色管理
 * </p>
 *
 * @author 非洲铜
 * @since 2022-12-11
 */
@Slf4j
@RestController
@RequestMapping("/sys/role")
@AllArgsConstructor
public class SysRoleController {
    private final SysRoleService sysRoleService;


    @GetMapping("/page")
    public R<IPage<SysRoleVO>> page(@Validated SysRoleParam sysRoleParam) {
        return R.ok(sysRoleService.selectPage(sysRoleParam));
    }

    @GetMapping("/list")
    public R<List<SysRoleVO>> list() {
        List<SysRoleVO> sysRoleVOS = sysRoleService.selectList();
        return R.ok(sysRoleVOS);
    }


    @GetMapping("/{id}")
    public R<SysRoleVO> get(@PathVariable("id") Long id) {
        SysRoleVO sysRoleVO = sysRoleService.getRole(id);
        return R.ok(sysRoleVO);
    }


    @PostMapping("/save")
    public R<Void> save(@RequestBody @Validated SysRoleVO sysRoleVO) {
        sysRoleService.save(sysRoleVO);
        return R.ok();
    }


    @PostMapping("/update")
    public R<Void> update(@RequestBody @Validated SysRoleVO sysRoleVO) {
        sysRoleService.update(sysRoleVO);
        return R.ok();
    }


}
